@model SummaryModel
@using Logistics.Web.Models.Order;
@using Nop.Core.Domain.Logistics;

@using (Html.BeginForm("Finalize", "Order", FormMethod.Post, new { id = "finalize-edit-form" }))
{
    var loc = Model.Locations.FirstOrDefault();
    <div class="col-xs-12">
        <h2>Order Confirmation</h2>
        @Html.HiddenFor(model => model.UserId)
        @Html.HiddenFor(model => model.CreditCardId)
        <div class="pickup-address-container section-wrapper">
            <div class="col-xs-12 col-md-6">
                <h3>Pickup Address</h3>
                @if (loc.UserAddress != null)
                {
                    @Html.Hidden("pickupAddressId", loc.UserAddress.Id)
                    <div class="name-pickup">
                        <b>
                            @if (String.IsNullOrEmpty(loc.UserAddress.Company))
                            {@loc.UserAddress.FirstName<text>&nbsp;</text>@loc.UserAddress.LastName }
                            else
                            { @loc.UserAddress.Company }
                        </b>
                    </div>
                    <div class="address-pickup">
                        @if (!String.IsNullOrEmpty(loc.UserAddress.Address2))
                        {@loc.UserAddress.Address2<text>&nbsp;</text>}@loc.UserAddress.Address1
                    </div>
                    <div class="city-province-zip-pickup">@loc.UserAddress.City, @loc.UserAddress.StateProvinceName @loc.UserAddress.ZipPostalCode</div>
                    <div class="number-pickup">
                        @if (!String.IsNullOrEmpty(loc.UserAddress.CellPhoneNumber))
                        {@loc.UserAddress.CellPhoneNumber}
                        else if (!String.IsNullOrEmpty(loc.UserAddress.PhoneNumber))
                        {@loc.UserAddress.PhoneNumber}
                    </div>
                    <div class="email-delivery">
                         @loc.UserAddress.Email
                    </div>
                }
            </div>
            @if (!String.IsNullOrEmpty(loc.PickupTimeStr))
            {
                <div class="col-xs-12 col-md-6">
                    <h3>Estimated Pickup Time</h3>
                    <div>
                        @loc.PickupTimeUserSelected
                        @*@loc.PickupTimeStr*@
                    </div>
                </div>

            }
            <div class="clear"></div>
            <div class="finalize-button row">
                <div class="col-xs-12 col-md-4">
                    <input type="button" value="Change" data-url="@Url.Action("PageRequest", "Order")" data-name="request" data-value="@CommonValues.PickupAddressViewName" class="btn btn-normal form-control" />
                </div>
            </div>
            <div class="clear"></div>
        </div>

        <div class="delivery-address-container section-wrapper">
            <div class="col-xs-12">
                <h3>Delivery Address</h3>
                @if (loc.Address != null)
                {
                    @Html.Hidden("deliveryAddressId", loc.Address.Id)
                    <div class="name-delivery">
                        <strong>
                            @if (String.IsNullOrEmpty(loc.Address.Company))
                            {@loc.Address.FirstName<text>&nbsp;</text>@loc.Address.LastName }
                            else
                            { @loc.Address.Company }
                        </strong>
                    </div>
                    <div class="address-delivery">
                        @if (!String.IsNullOrEmpty(loc.Address.Address2))
                        {@loc.Address.Address2<text>&nbsp;</text>}@loc.Address.Address1
                    </div>
                    <div class="city-province-zip-delivery">@loc.Address.City, @loc.Address.StateProvinceName @loc.Address.ZipPostalCode</div>
                    <div class="number-delivery">
                        @if (!String.IsNullOrEmpty(loc.Address.CellPhoneNumber))
                        {@loc.Address.CellPhoneNumber}
                        else if (!String.IsNullOrEmpty(loc.Address.PhoneNumber))
                        {@loc.Address.PhoneNumber}
                    </div>
                    <div class="email-delivery">
                        @loc.Address.Email
                    </div>
                    <div class="finalize-button row">
                        <div class="col-xs-12 col-md-4">
                            <input type="button" value="Change" data-url="@Url.Action("Pagerequest", "Order")" data-name="request" data-value="@CommonValues.DeliveryAddressViewName" class="btn btn-normal form-control" />
                        </div>
                    </div>
                }
            </div>
            <div class="clear"></div>
        </div>

        <div class="packages-container section-wrapper">
            <div class="col-xs-12">
                <h3>Packages</h3>
                @if (Model.CurrentPackages.Count > 0)
                {
                    <div class="row">
                        @Html.Hidden("packageCount", Model.CurrentPackages.Count)
                        @foreach (var package in Model.CurrentPackages)
                        {
                            <div class="finalize-package col-xs-6 col-ms-6 col-sm-4 col-md-4 col-lg-3">
                                <h5>
                                    Package #@if (package.Id == 0)
                                    {<text>1</text>}
                                    else
                                    {@package.Id} <b>($@package.Charge)</b>
                                </h5>
                                <div class="package-container">
                                    @if (package.PackagePreset.HasValue)
                                    {
                                        switch (package.PackagePreset.Value)
                                        {
                                            case (int)PackagePreset.Letter:
                                                <div class="image">
                                                    <img src="/content/images/size-lettersize-small.png" alt="Letter size" />
                                                </div>
                                                <div class="text">Letter</div>
                                                break;
                                            case (int)PackagePreset.Small:
                                            <div class="image">
                                                <img src="/content/images/size-small-small.png" alt="Small size" />
                                            </div>
                                            <div class="text">Small</div>
                                                break;
                                            case (int)PackagePreset.Medium:
                                            <div class="image">
                                                <img src="/content/images/size-medium-small.png" alt="Medium size" />
                                            </div>
                                            <div class="text">Medium</div>
                                                break;
                                            case (int)PackagePreset.Large:
                                            <div class="image">
                                                <img src="/content/images/size-large-small.png" alt="Large size" />
                                            </div>
                                            <div class="text">Large</div>
                                                break;
                                            case (int)PackagePreset.ExtraLarge:
                                            <div class="image">
                                                <img src="/content/images/size-extralarge-small.png" alt="Extra large size" />
                                            </div>
                                            <div class="text">Extra Large</div>
                                                break;
                                            case (int)PackagePreset.None:
                                                break;
                                        }
                                    }
                                    else
                                    {
                                        <div class="image">
                                            <span>Custom</span>
                                        </div>
                                        <div class="text">Custom</div>
                                    }
                                    <input type="button" value="Change" data-url="@Url.Action("Pagerequest", "Order")" data-name="request" data-value="@CommonValues.PackageInfoViewName" data-name2="packageId" data-value2="@package.Id" class="btn btn-normal form-control" />
                                </div>
                            </div>
                        }
                    </div>
                }
                else
                {
                    <div>No package information available.</div>
                }


            </div>
            <div class="clear"></div>
        </div>

        <div class="payment-container section-wrapper">
            <div class="col-xs-12">
                <h3>Payment Info</h3>

                @Html.Hidden("total", Model.Total)
                @if (Model.Total == 0 && !Model.IsPaymentExempt)
                {
                    <div>Payment not required for this order.</div>
                }
                else if (Model.IsPaymentExempt)
                {
                    <div>Shipping orders are billed semi-monthly.</div>
                }
                else if (Model.PaymentInfo != null && Model.Total > 0)
                {
                    <div class="card-holder">Card Holder: @Model.PaymentInfo.CardHolder</div>
                    <div class="card-number">Card Number: @Model.PaymentInfo.CardNumber</div>
                    <div class="card-type">Card Type: @Model.PaymentInfo.CardType</div>
                    <div class="card-expiry">Expiry Date: @Model.PaymentInfo.ExpMonth/@Model.PaymentInfo.ExpYear</div>
                    @*<input type="hidden" value="@Model.PaymentInfo.Id" name="createCradId">*@
                    <div class="finalize-button row">
                        <div class="col-xs-12 col-md-4">
                            <input type="button" value="Change" data-url="@Url.Action("Pagerequest", "Order")" data-name="request" data-value="@CommonValues.PaymentInfoViewName" class="btn btn-normal form-control" />
                        </div>
                    </div>
                }
                else
                {
                    <div>Payment information is unavailable.</div>
                }
            </div>
            <div class="clear"></div>
        </div>
        <div class="finalize-button finalize-order-button row">
            <div class="col-xs-12 col-md-4">
                <input type="button" class="btn btn-normal form-control" data-action="clearOrder" data-url="@Url.Action("RemovePendingorder", "Order")" value="Cancel & Restart" />
            </div>
            <div class="col-xs-12 col-md-4">
                <input type="button" class="btn btn-danger form-control" data-action="submit" value="Confirm and Process Orders" />
            </div>

            <div class="clear"></div>
        </div>
    </div>
}
